<?php
function excuteSQL($files, $mysqli)
{
    foreach ($files as $fileName) {
        $str = file_get_contents($fileName);
        $strs = split(";", $str);
        foreach ($strs as $query) {
            if (trim($query) != "") {
                include '../web/common/database.php';
                $mysqli->query($query);
                $mysqli->close();
            }
        }
    }
}
function excuteProcedure($files, $mysqli)
{
    foreach ($files as $fileName) {
        $str = file_get_contents($fileName);
        $strs = split("\/\*\*\/", $str);
        foreach ($strs as $query) {
            if (trim($query) != "") {
                include '../web/common/database.php';
                $mysqli->query($query);
                $mysqli->close();
            }
        }
    }
}
function get_all_files( $path ){
    $list = array();
    foreach( glob( $path . '/*') as $item ){
        if( is_dir( $item ) ){
            $list = array_merge( $list , get_all_files( $item ) );
        }
        else{
            $list[] = $item;
        }
    }
    return $list;
}
$files = get_all_files("../sql/table");
excuteSQL($files, $mysqli);
$files = get_all_files("../sql/procedure");
excuteProcedure($files, $mysqli);
$files = get_all_files("../sql/operate");
excuteSQL($files, $mysqli);
?>
